package com.guoxin.concurrentprogramming.chapter2;


/**
 * @author guoxin
 * @date 2019/7/15
 */
public class AccountingVol implements Runnable {
    static int i=0;
    @Override
    public void run() {
        for(int i=0;i<10000000;i++){
            increase();
        }
    }

    private synchronized void increase(){
        i++;
    }

    public static void main(String[] args) throws InterruptedException {
        AccountingVol av = new AccountingVol();

        Thread t1 = new Thread(av, "T1");
        Thread t2 = new Thread(av, "T2");

        t1.start();
        t2.start();

        t1.join();
        t2.join();
        System.out.println(i);
    }
}
